package zzps.exeed.plugin.undertow;

import zzps.exeed.kernel.core.AppContext;
import zzps.exeed.kernel.core.Plugin;
import zzps.exeed.kernel.event.EventBroadcaster;
import zzps.exeed.kernel.holder.PandaHolder;
import zzps.exeed.web.ServerProp;
import zzps.exeed.web.WebPlugin;
import zzps.exeed.web.servlet.ExeedServlet;

public class UndertowPlugin implements Plugin {

    UndertowWebServer webServer;

    @Override
    public void start(AppContext context) {
        PandaHolder<ServerProp> panda = context.container().getPanda(ServerProp.class);
//        ServerProp serverProp = new ServerProp();
//        serverProp.setPort(8081);
        ExeedServlet exeedServlet = new ExeedServlet(context);
        webServer = new UndertowWebServer(panda.get(), exeedServlet);
//        webServer.start();
        UndertowStartEventListener undertowStartEventListener = new UndertowStartEventListener(webServer);
        EventBroadcaster.subscribe(undertowStartEventListener);
    }

    @Override
    public void stop() {
        webServer.stop();
    }

    @Override
    public Class<? extends Plugin>[] after() {
        return new Class[]{WebPlugin.class};
    }
}
